using SS.core;
using System;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Globalization;
using System.Threading;
using System.Windows.Forms;
namespace SS
{
	public class FrmupdtGproduct : Form
	{
		private IContainer components = null;
		private GroupBox groupBox1;
		private Label label3;
		private TextBox TxtGpName;
		private Label label4;
		private TextBox TxtGpNote;
		private ToolTip toolTip1;
		private Button tSBClose;
		private Button tSBSave;
		private Button tSBAdd;
		private Button btnDel;
		private DataGridView dgvGroupProducts;
		private DataGridViewTextBoxColumn Column1;
		private DataGridViewTextBoxColumn Column2;
		private DataGridViewTextBoxColumn Column3;
		private Label label1;
		private BindingNavigator bindingNavigator1;
		private ToolStripLabel bindingNavigatorCountItem;
		private ToolStripButton bindingNavigatorMoveFirstItem;
		private ToolStripButton bindingNavigatorMovePreviousItem;
		private ToolStripSeparator bindingNavigatorSeparator;
		private ToolStripTextBox bindingNavigatorPositionItem;
		private ToolStripSeparator bindingNavigatorSeparator1;
		private ToolStripButton bindingNavigatorMoveNextItem;
		private ToolStripButton bindingNavigatorMoveLastItem;
		private ToolStripSeparator bindingNavigatorSeparator2;
		private Func objFunc = new Func();
		public int gPID;
		public bool checkUpt = false;
		private string strConnection = "";
		protected override void Dispose(bool disposing)
		{
			if (disposing && this.components != null)
			{
				this.components.Dispose();
			}
			base.Dispose(disposing);
		}
		private void InitializeComponent()
		{
			this.components = new Container();
			DataGridViewCellStyle dataGridViewCellStyle = new DataGridViewCellStyle();
			ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof(FrmupdtGproduct));
			this.groupBox1 = new GroupBox();
			this.label4 = new Label();
			this.TxtGpNote = new TextBox();
			this.label3 = new Label();
			this.TxtGpName = new TextBox();
			this.toolTip1 = new ToolTip(this.components);
			this.tSBClose = new Button();
			this.tSBSave = new Button();
			this.tSBAdd = new Button();
			this.btnDel = new Button();
			this.dgvGroupProducts = new DataGridView();
			this.Column1 = new DataGridViewTextBoxColumn();
			this.Column2 = new DataGridViewTextBoxColumn();
			this.Column3 = new DataGridViewTextBoxColumn();
			this.label1 = new Label();
			this.bindingNavigator1 = new BindingNavigator(this.components);
			this.bindingNavigatorCountItem = new ToolStripLabel();
			this.bindingNavigatorMoveFirstItem = new ToolStripButton();
			this.bindingNavigatorMovePreviousItem = new ToolStripButton();
			this.bindingNavigatorSeparator = new ToolStripSeparator();
			this.bindingNavigatorPositionItem = new ToolStripTextBox();
			this.bindingNavigatorSeparator1 = new ToolStripSeparator();
			this.bindingNavigatorMoveNextItem = new ToolStripButton();
			this.bindingNavigatorMoveLastItem = new ToolStripButton();
			this.bindingNavigatorSeparator2 = new ToolStripSeparator();
			this.groupBox1.SuspendLayout();
			((ISupportInitialize)this.dgvGroupProducts).BeginInit();
			((ISupportInitialize)this.bindingNavigator1).BeginInit();
			this.bindingNavigator1.SuspendLayout();
			base.SuspendLayout();
			this.groupBox1.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right);
			this.groupBox1.BackColor = Color.Transparent;
			this.groupBox1.Controls.Add(this.label4);
			this.groupBox1.Controls.Add(this.TxtGpNote);
			this.groupBox1.Controls.Add(this.label3);
			this.groupBox1.Controls.Add(this.TxtGpName);
			this.groupBox1.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.groupBox1.Location = new Point(7, 466);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new Size(886, 87);
			this.groupBox1.TabIndex = 2;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "Thông tin chi tiết";
			this.label4.BackColor = Color.FromArgb(255, 255, 192);
			this.label4.BorderStyle = BorderStyle.Fixed3D;
			this.label4.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.label4.Location = new Point(7, 51);
			this.label4.Name = "label4";
			this.label4.Size = new Size(71, 22);
			this.label4.TabIndex = 9;
			this.label4.Text = "Ghi chú :";
			this.label4.TextAlign = ContentAlignment.MiddleRight;
			this.TxtGpNote.Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
			this.TxtGpNote.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.TxtGpNote.Location = new Point(80, 51);
			this.TxtGpNote.Name = "TxtGpNote";
			this.TxtGpNote.Size = new Size(795, 22);
			this.TxtGpNote.TabIndex = 4;
			this.TxtGpNote.Leave += new EventHandler(this.TxtGpNote_Leave);
			this.TxtGpNote.KeyPress += new KeyPressEventHandler(this.TxtGpNote_KeyPress);
			this.TxtGpNote.Enter += new EventHandler(this.TxtGpNote_Enter);
			this.label3.BackColor = Color.FromArgb(255, 255, 192);
			this.label3.BorderStyle = BorderStyle.Fixed3D;
			this.label3.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.label3.Location = new Point(7, 23);
			this.label3.Name = "label3";
			this.label3.Size = new Size(71, 22);
			this.label3.TabIndex = 7;
			this.label3.Text = "Tên gọi :";
			this.label3.TextAlign = ContentAlignment.MiddleRight;
			this.TxtGpName.Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
			this.TxtGpName.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.TxtGpName.Location = new Point(80, 24);
			this.TxtGpName.Name = "TxtGpName";
			this.TxtGpName.Size = new Size(795, 22);
			this.TxtGpName.TabIndex = 3;
			this.TxtGpName.Leave += new EventHandler(this.TxtGpName_Leave);
			this.TxtGpName.KeyPress += new KeyPressEventHandler(this.TxtGpName_KeyPress);
			this.TxtGpName.Enter += new EventHandler(this.TxtGpName_Enter);
			this.tSBClose.Anchor = (AnchorStyles.Bottom | AnchorStyles.Right);
			this.tSBClose.BackColor = SystemColors.ButtonFace;
			this.tSBClose.Cursor = Cursors.Hand;
			this.tSBClose.FlatAppearance.BorderColor = Color.Gray;
			this.tSBClose.FlatStyle = FlatStyle.System;
			this.tSBClose.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.tSBClose.ImageAlign = ContentAlignment.MiddleLeft;
//			this.tSBClose.ImeMode = ImeMode.NoControl;
			this.tSBClose.Location = new Point(793, 561);
			this.tSBClose.Name = "tSBClose";
			this.tSBClose.Size = new Size(100, 30);
			this.tSBClose.TabIndex = 8;
			this.tSBClose.Text = "Thoát  [ ESC ]";
			this.tSBClose.UseVisualStyleBackColor = false;
			this.tSBClose.Click += new EventHandler(this.tSBClose_Click);
			this.tSBSave.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left);
			this.tSBSave.BackColor = SystemColors.ButtonFace;
			this.tSBSave.Cursor = Cursors.Hand;
			this.tSBSave.FlatAppearance.BorderColor = Color.Gray;
			this.tSBSave.FlatStyle = FlatStyle.System;
			this.tSBSave.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.tSBSave.ImageAlign = ContentAlignment.MiddleLeft;
//			this.tSBSave.ImeMode = ImeMode.NoControl;
			this.tSBSave.Location = new Point(116, 561);
			this.tSBSave.Name = "tSBSave";
			this.tSBSave.Size = new Size(100, 30);
			this.tSBSave.TabIndex = 6;
			this.tSBSave.Text = "Ghi nhận  [ F6 ]";
			this.tSBSave.UseVisualStyleBackColor = false;
			this.tSBSave.Click += new EventHandler(this.tSBSave_Click);
			this.tSBAdd.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left);
			this.tSBAdd.BackColor = SystemColors.ButtonFace;
			this.tSBAdd.Cursor = Cursors.Hand;
			this.tSBAdd.FlatAppearance.BorderColor = Color.Gray;
			this.tSBAdd.FlatStyle = FlatStyle.System;
			this.tSBAdd.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.tSBAdd.ImageAlign = ContentAlignment.MiddleLeft;
			//this.tSBAdd.ImeMode = ImeMode.NoControl;
			this.tSBAdd.Location = new Point(8, 561);
			this.tSBAdd.Name = "tSBAdd";
			this.tSBAdd.Size = new Size(106, 30);
			this.tSBAdd.TabIndex = 5;
			this.tSBAdd.Text = "Thêm nhóm [ F4 ]";
			this.tSBAdd.UseVisualStyleBackColor = false;
			this.tSBAdd.Click += new EventHandler(this.tSBAdd_Click);
			this.btnDel.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left);
			this.btnDel.BackColor = SystemColors.ButtonFace;
			this.btnDel.Cursor = Cursors.Hand;
			this.btnDel.FlatAppearance.BorderColor = Color.Gray;
			this.btnDel.FlatStyle = FlatStyle.System;
			this.btnDel.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnDel.ImageAlign = ContentAlignment.MiddleLeft;
			this.btnDel.Location = new Point(218, 561);
			this.btnDel.Name = "btnDel";
			this.btnDel.Size = new Size(105, 30);
			this.btnDel.TabIndex = 7;
			this.btnDel.Text = "Xoá nhóm [ F8 ]";
			this.btnDel.UseVisualStyleBackColor = false;
			this.btnDel.Click += new EventHandler(this.btnDel_Click);
			this.dgvGroupProducts.AllowUserToAddRows = false;
			this.dgvGroupProducts.AllowUserToDeleteRows = false;
			this.dgvGroupProducts.AllowUserToResizeColumns = false;
			this.dgvGroupProducts.AllowUserToResizeRows = false;
			dataGridViewCellStyle.BackColor = Color.FromArgb(192, 255, 255);
			dataGridViewCellStyle.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
			this.dgvGroupProducts.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle;
			this.dgvGroupProducts.Anchor = (AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right);
			this.dgvGroupProducts.BackgroundColor = Color.White;
			this.dgvGroupProducts.BorderStyle = BorderStyle.Fixed3D;
			this.dgvGroupProducts.ColumnHeadersHeight = 26;
			this.dgvGroupProducts.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
			this.dgvGroupProducts.Columns.AddRange(new DataGridViewColumn[]
			{
				this.Column1,
				this.Column2,
				this.Column3
			});
			this.dgvGroupProducts.Cursor = Cursors.Hand;
			this.dgvGroupProducts.EnableHeadersVisualStyles = false;
			this.dgvGroupProducts.Location = new Point(7, 38);
			this.dgvGroupProducts.Name = "dgvGroupProducts";
			this.dgvGroupProducts.ReadOnly = true;
			this.dgvGroupProducts.RowHeadersVisible = false;
			this.dgvGroupProducts.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing;
			this.dgvGroupProducts.RowTemplate.DefaultCellStyle.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
			this.dgvGroupProducts.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
			this.dgvGroupProducts.Size = new Size(886, 394);
			this.dgvGroupProducts.TabIndex = 0;
			this.dgvGroupProducts.CellEnter += new DataGridViewCellEventHandler(this.dgvGroupProducts_CellEnter);
			this.Column1.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.Column1.DataPropertyName = "GpID";
			this.Column1.HeaderText = "Số hiệu kho";
			this.Column1.MinimumWidth = 150;
			this.Column1.Name = "Column1";
			this.Column1.ReadOnly = true;
			this.Column1.Visible = false;
			this.Column1.Width = 150;
			this.Column2.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.Column2.DataPropertyName = "GpName";
			this.Column2.HeaderText = "Tên nhóm";
			this.Column2.MinimumWidth = 300;
			this.Column2.Name = "Column2";
			this.Column2.ReadOnly = true;
			this.Column2.Width = 300;
			this.Column3.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
			this.Column3.DataPropertyName = "GpNote";
			this.Column3.HeaderText = "Diễn giải";
			this.Column3.Name = "Column3";
			this.Column3.ReadOnly = true;
			this.label1.Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
			this.label1.BackColor = Color.Transparent;
			this.label1.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 0);
			this.label1.Location = new Point(7, 12);
			this.label1.Name = "label1";
			this.label1.Size = new Size(887, 23);
			this.label1.TabIndex = 69;
			this.label1.Text = "DANH MỤC NHÓM THUỐC";
			this.label1.TextAlign = ContentAlignment.MiddleCenter;
			this.bindingNavigator1.AddNewItem = null;
			this.bindingNavigator1.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right);
			this.bindingNavigator1.AutoSize = false;
			this.bindingNavigator1.BackColor = SystemColors.ButtonFace;
			this.bindingNavigator1.CountItem = this.bindingNavigatorCountItem;
			this.bindingNavigator1.CountItemFormat = "/ {0}";
			this.bindingNavigator1.DeleteItem = null;
			this.bindingNavigator1.Dock = DockStyle.None;
			this.bindingNavigator1.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.bindingNavigator1.GripStyle = ToolStripGripStyle.Hidden;
			this.bindingNavigator1.Items.AddRange(new ToolStripItem[]
			{
				this.bindingNavigatorMoveFirstItem,
				this.bindingNavigatorMovePreviousItem,
				this.bindingNavigatorSeparator,
				this.bindingNavigatorPositionItem,
				this.bindingNavigatorCountItem,
				this.bindingNavigatorSeparator1,
				this.bindingNavigatorMoveNextItem,
				this.bindingNavigatorMoveLastItem,
				this.bindingNavigatorSeparator2
			});
			this.bindingNavigator1.Location = new Point(7, 435);
			this.bindingNavigator1.MoveFirstItem = this.bindingNavigatorMoveFirstItem;
			this.bindingNavigator1.MoveLastItem = this.bindingNavigatorMoveLastItem;
			this.bindingNavigator1.MoveNextItem = this.bindingNavigatorMoveNextItem;
			this.bindingNavigator1.MovePreviousItem = this.bindingNavigatorMovePreviousItem;
			this.bindingNavigator1.Name = "bindingNavigator1";
			this.bindingNavigator1.PositionItem = this.bindingNavigatorPositionItem;
			this.bindingNavigator1.RenderMode = ToolStripRenderMode.Professional;
			this.bindingNavigator1.Size = new Size(886, 25);
			this.bindingNavigator1.TabIndex = 1;
			this.bindingNavigator1.Text = "bindingNavigator1";
			this.bindingNavigatorCountItem.Name = "bindingNavigatorCountItem";
			this.bindingNavigatorCountItem.Size = new Size(28, 22);
			this.bindingNavigatorCountItem.Text = "/ {0}";
			this.bindingNavigatorCountItem.ToolTipText = "Total number of items";
			this.bindingNavigatorMoveFirstItem.DisplayStyle = ToolStripItemDisplayStyle.Image;
			//this.bindingNavigatorMoveFirstItem.Image = (Image)componentResourceManager.GetObject("bindingNavigatorMoveFirstItem.Image");
			this.bindingNavigatorMoveFirstItem.Name = "bindingNavigatorMoveFirstItem";
			this.bindingNavigatorMoveFirstItem.RightToLeftAutoMirrorImage = true;
			this.bindingNavigatorMoveFirstItem.Size = new Size(23, 22);
			this.bindingNavigatorMoveFirstItem.Text = "Move first";
			this.bindingNavigatorMovePreviousItem.DisplayStyle = ToolStripItemDisplayStyle.Image;
			//this.bindingNavigatorMovePreviousItem.Image = (Image)componentResourceManager.GetObject("bindingNavigatorMovePreviousItem.Image");
			this.bindingNavigatorMovePreviousItem.Name = "bindingNavigatorMovePreviousItem";
			this.bindingNavigatorMovePreviousItem.RightToLeftAutoMirrorImage = true;
			this.bindingNavigatorMovePreviousItem.Size = new Size(23, 22);
			this.bindingNavigatorMovePreviousItem.Text = "Move previous";
			this.bindingNavigatorSeparator.Name = "bindingNavigatorSeparator";
			this.bindingNavigatorSeparator.Size = new Size(6, 25);
			this.bindingNavigatorPositionItem.AccessibleName = "Position";
			this.bindingNavigatorPositionItem.AutoSize = false;
			this.bindingNavigatorPositionItem.BackColor = SystemColors.ButtonFace;
			this.bindingNavigatorPositionItem.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.bindingNavigatorPositionItem.Name = "bindingNavigatorPositionItem";
			this.bindingNavigatorPositionItem.Size = new Size(50, 21);
			this.bindingNavigatorPositionItem.Text = "0";
			this.bindingNavigatorPositionItem.TextBoxTextAlign = HorizontalAlignment.Center;
			this.bindingNavigatorPositionItem.ToolTipText = "Current position";
			this.bindingNavigatorSeparator1.Name = "bindingNavigatorSeparator1";
			this.bindingNavigatorSeparator1.Size = new Size(6, 25);
			this.bindingNavigatorMoveNextItem.DisplayStyle = ToolStripItemDisplayStyle.Image;
			//this.bindingNavigatorMoveNextItem.Image = (Image)componentResourceManager.GetObject("bindingNavigatorMoveNextItem.Image");
			this.bindingNavigatorMoveNextItem.Name = "bindingNavigatorMoveNextItem";
			this.bindingNavigatorMoveNextItem.RightToLeftAutoMirrorImage = true;
			this.bindingNavigatorMoveNextItem.Size = new Size(23, 22);
			this.bindingNavigatorMoveNextItem.Text = "Move next";
			this.bindingNavigatorMoveLastItem.DisplayStyle = ToolStripItemDisplayStyle.Image;
			//this.bindingNavigatorMoveLastItem.Image = (Image)componentResourceManager.GetObject("bindingNavigatorMoveLastItem.Image");
			this.bindingNavigatorMoveLastItem.Name = "bindingNavigatorMoveLastItem";
			this.bindingNavigatorMoveLastItem.RightToLeftAutoMirrorImage = true;
			this.bindingNavigatorMoveLastItem.Size = new Size(23, 22);
			this.bindingNavigatorMoveLastItem.Text = "Move last";
			this.bindingNavigatorSeparator2.Name = "bindingNavigatorSeparator2";
			this.bindingNavigatorSeparator2.Size = new Size(6, 25);
			base.AutoScaleDimensions = new SizeF(7f, 15f);
			//base.AutoScaleMode = AutoScaleMode.Font;
			base.ClientSize = new Size(900, 600);
			base.Controls.Add(this.bindingNavigator1);
			base.Controls.Add(this.label1);
			base.Controls.Add(this.dgvGroupProducts);
			base.Controls.Add(this.btnDel);
			base.Controls.Add(this.tSBClose);
			base.Controls.Add(this.tSBSave);
			base.Controls.Add(this.tSBAdd);
			base.Controls.Add(this.groupBox1);
			this.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 0);
			//base.Icon = (System.Drawing.Icon)componentResourceManager.GetObject("$this.Icon");
			//base.Icon = (Icon)componentResourceManager.GetObject("$this.Icon");
			base.KeyPreview = true;
			base.MaximizeBox = false;
			base.MinimizeBox = false;
			base.Name = "FrmupdtGproduct";
			base.ShowInTaskbar = false;
			base.StartPosition = FormStartPosition.CenterScreen;
			this.Text = "NHÓM THUỐC, VẬT TƯ";
			base.Load += new EventHandler(this.FrmupdtGproduct_Load);
			base.KeyDown += new KeyEventHandler(this.FrmupdtGproduct_KeyDown);
			this.groupBox1.ResumeLayout(false);
			this.groupBox1.PerformLayout();
			((ISupportInitialize)this.dgvGroupProducts).EndInit();
			((ISupportInitialize)this.bindingNavigator1).EndInit();
			this.bindingNavigator1.ResumeLayout(false);
			this.bindingNavigator1.PerformLayout();
			base.ResumeLayout(false);
		}
		public FrmupdtGproduct()
		{
			this.InitializeComponent();
		}
		private void tSBClose_Click(object sender, EventArgs e)
		{
			base.Close();
		}
		private void txtGpParent_KeyPress(object sender, KeyPressEventArgs e)
		{
			if (e.KeyChar == '\r')
			{
				this.TxtGpName.Focus();
			}
		}
		private void TxtGpName_Enter(object sender, EventArgs e)
		{
			this.TxtGpName.BackColor = Color.Aqua;
		}
		private void TxtGpName_Leave(object sender, EventArgs e)
		{
			this.TxtGpName.BackColor = Color.White;
		}
		private void TxtGpName_KeyPress(object sender, KeyPressEventArgs e)
		{
			if (e.KeyChar == '\r')
			{
				this.TxtGpNote.Focus();
			}
		}
		private void TxtGpNote_Enter(object sender, EventArgs e)
		{
			this.TxtGpNote.BackColor = Color.Aqua;
		}
		private void TxtGpNote_Leave(object sender, EventArgs e)
		{
			this.TxtGpNote.BackColor = Color.White;
		}
		private void TxtGpNote_KeyPress(object sender, KeyPressEventArgs e)
		{
			if (e.KeyChar == '\r')
			{
				this.tSBSave.PerformClick();
			}
		}
		private bool CheckName(string tempName, int tempID)
		{
			bool result = false;
			SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
			SqlCommand sqlCommand = new SqlCommand();
			sqlCommand.Connection = sqlConnection;
			sqlCommand.CommandText = string.Concat(new object[]
			{
				"SELECT TOP 1 GpName FROM [TabGproducts] WHERE [GpName] = '",
				tempName,
				"' AND [GpID]<>",
				tempID
			});
			sqlConnection.Open();
			SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
			if (sqlDataReader.HasRows)
			{
				result = true;
			}
			sqlDataReader.Close();
			sqlDataReader.Dispose();
			sqlConnection.Close();
			sqlConnection.Dispose();
			return result;
		}
		private void tSBSave_Click(object sender, EventArgs e)
		{
			if (this.TxtGpName.Text == "")
			{
				MessageBox.Show("Bạn cần cung cấp tên nhóm hàng hoá!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				this.TxtGpName.Focus();
			}
			else
			{
				if (this.CheckName(this.TxtGpName.Text.Trim(), this.gPID))
				{
					MessageBox.Show("Tên nhóm hàng hoá đã tồn tại!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
					this.TxtGpName.Focus();
				}
				else
				{
					SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
					sqlConnection.Open();
					SqlCommand sqlCommand = new SqlCommand("ActionOnTabGproducts", sqlConnection);
					sqlCommand.CommandType = CommandType.StoredProcedure;
					sqlCommand.Parameters.Add("@GpID", SqlDbType.Int);
					sqlCommand.Parameters.Add("@GpName", SqlDbType.NVarChar);
					sqlCommand.Parameters.Add("@GpNote", SqlDbType.NVarChar);
					sqlCommand.Parameters["@GpID"].Value = this.gPID;
					sqlCommand.Parameters["@GpName"].Value = this.TxtGpName.Text;
					sqlCommand.Parameters["@GpNote"].Value = this.TxtGpNote.Text;
					sqlCommand.ExecuteNonQuery();
					sqlConnection.Close();
					sqlConnection.Dispose();
					groupProducts groupProducts = new groupProducts();
					groupProducts.loadToDataGridView(this.dgvGroupProducts, this.bindingNavigator1);
					this.checkUpt = true;
				}
			}
		}
		private void LoadData(string _gPID)
		{
			GProduct gProduct = new GProduct();
			SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
			SqlCommand sqlCommand = new SqlCommand();
			sqlCommand.Connection = sqlConnection;
			sqlCommand.CommandText = "SELECT * FROM TabGproducts WHERE GpID = '" + _gPID + "' ORDER BY [GpName]";
			sqlConnection.Open();
			SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
			if (sqlDataReader.HasRows)
			{
				while (sqlDataReader.Read())
				{
					this.TxtGpName.Text = sqlDataReader["GpName"].ToString();
					this.TxtGpNote.Text = sqlDataReader["GpNote"].ToString();
				}
			}
			sqlConnection.Close();
			sqlConnection.Dispose();
		}
		private void FrmupdtGproduct_Load(object sender, EventArgs e)
		{
			Program.strConnectionString = this.objFunc.strConnectionString;
			groupProducts groupProducts = new groupProducts();
			groupProducts.loadToDataGridView(this.dgvGroupProducts, this.bindingNavigator1);
			Thread.CurrentThread.CurrentCulture = new CultureInfo("en-us");
			if (this.gPID != 0)
			{
				this.LoadData(this.gPID.ToString());
			}
		}
		private void tSBAdd_Click(object sender, EventArgs e)
		{
			this.gPID = 0;
			this.TxtGpName.Text = "";
			this.TxtGpNote.Text = "";
			this.TxtGpName.Focus();
		}
		public void DeleteGProducts(int _GpID)
		{
			SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
			SqlCommand sqlCommand = new SqlCommand("DELETE FROM TabGproducts WHERE  [GpID] = @GpID", sqlConnection);
			sqlCommand.Parameters.Add("@GpID", SqlDbType.Int);
			sqlCommand.Parameters["@GpID"].Value = _GpID;
			sqlConnection.Open();
			sqlCommand.ExecuteNonQuery();
			sqlConnection.Close();
			sqlConnection.Dispose();
		}
		private void btnDel_Click(object sender, EventArgs e)
		{
			try
			{
				groupProducts groupProducts = new groupProducts();
				if (MessageBox.Show("Có phải bạn muốn xoá mục được chọn không?\r\n\r\nBấm YES nếu đồng ý xoá, Bấm NO để bỏ qua!", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
				{
					bool flag = this.CheckGroupExistInRep(this.gPID.ToString());
					if (flag)
					{
						MessageBox.Show("Không được xóa nhóm hàng này vì nó đang được sử dụng !\r\n\r\nHãy xoá hết các sản phẩm trong nhóm trước khi xoá nhóm.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
						groupProducts.loadToDataGridView(this.dgvGroupProducts, this.bindingNavigator1);
						return;
					}
					groupProducts.del(this.gPID.ToString());
				}
				groupProducts.loadToDataGridView(this.dgvGroupProducts, this.bindingNavigator1);
			}
			catch
			{
			}
		}
		private bool CheckGroupExistInRep(string tmpGroup)
		{
			bool result = false;
			SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
			sqlConnection.Open();
			try
			{
				SqlCommand sqlCommand = sqlConnection.CreateCommand();
				sqlCommand.CommandText = "SELECT TOP 1 PID FROM [TabProducts] WHERE [GpID] = " + tmpGroup;
				SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
				if (sqlDataReader.HasRows)
				{
					result = true;
				}
				sqlDataReader.Close();
				sqlDataReader.Dispose();
			}
			catch
			{
			}
			sqlConnection.Close();
			sqlConnection.Dispose();
			return result;
		}
		private void lvAgent_KeyPress(object sender, KeyPressEventArgs e)
		{
			if (e.KeyChar == '\r')
			{
				this.TxtGpName.Focus();
			}
		}
		private void FrmupdtGproduct_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.KeyCode == Keys.F4)
			{
				this.tSBAdd.PerformClick();
			}
			else
			{
				if (e.KeyCode == Keys.F6)
				{
					this.tSBSave.PerformClick();
				}
				else
				{
					if (e.KeyCode == Keys.F8)
					{
						this.btnDel.PerformClick();
					}
					else
					{
						if (e.KeyCode == Keys.Escape)
						{
							base.Close();
						}
					}
				}
			}
		}
		private void dgvGroupProducts_CellEnter(object sender, DataGridViewCellEventArgs e)
		{
			try
			{
				this.gPID = int.Parse(this.dgvGroupProducts.Rows[e.RowIndex].Cells["Column1"].Value.ToString());
				groupProducts groupProducts = new groupProducts();
				groupProducts.getInfo(this.gPID.ToString(), this.TxtGpName, this.TxtGpNote);
			}
			catch
			{
			}
		}
	}
}
